
package org.javaUtil.tool.Propertie;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

/**
 * 
 * get  Properties file data by key
 * @author muyi
 *
 */
public class PropertieUtil 
{
	private static Properties prop=new Properties();
	private static HashMap<String,String> hashMap=new HashMap<String,String>();
	
	
	/**
	 *  must set fileName 
	 *   fileName must put it down project src 
	 * @param fileName fileName
	 */
	public  PropertieUtil(String fileName)
	{
		
		try {
			prop.load(PropertieUtil.class.getClassLoader().getResourceAsStream(fileName));
			
			Enumeration<Object> en=prop.keys();
			while(en.hasMoreElements()){
				String key=(String) en.nextElement();
				String value=prop.getProperty(key);
				hashMap.put(key, value);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * getValue
	 * @param name key Name
	 * @return String
	 */
	public static String getValue(String name){
		if(hashMap.get(name)==null){
		   return	prop.getProperty(name);
		}
		return hashMap.get(name);
	}
	
}
